Various improvements to the existing set of preload tests * Align the test names with the rest of the tests, i.e. use '-' instead of '_'. * Add feature detection to make sure the tests consistently fail in non-supporting browsers. * Make sure that download verification is based on the URL's existence in ResourceTiming, rather on the overall number of resources downloaded, which can be misleading.
diff --git a/preload/link-header-preload-delay-onload.html b/preload/link-header-preload-delay-onload.html new file mode 100644 index 0000000..86d3b06 --- /dev/null +++ b/preload/link-header-preload-delay-onload.html 
@@ -0,0 +1,40 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/preload/resources/preload_helper.js"></script> +<script> + var t = async_test('Makes sure that Link headers preload resources and block window.onload after resource discovery'); +</script> +<body> +<style> + #background { + width: 200px; + height: 200px; + background-image: url(resources/square.png?background); + } +</style> +<link rel="stylesheet" href="resources/dummy.css"> +<script src="resources/dummy.js"></script> +<div id="background"></div> +<script> + document.write('<img src="resources/square.png">'); + window.addEventListener("load", t.step_func(function() { + verifyPreloadAndRTSupport(); + var entries = performance.getEntriesByType("resource"); + var found_background_first = false; + for (var i = 0; i < entries.length; ++i) { + var entry = entries[i]; + if (entry.name.indexOf("square") != -1) { + if (entry.name.indexOf("background") != -1) + found_background_first = true; + break; + } + } + assert_true(found_background_first); + verifyNumberOfDownloads("resources/square.png", 1); + verifyNumberOfDownloads("resources/square.png?background", 1); + verifyNumberOfDownloads("resources/dummy.js", 1); + verifyNumberOfDownloads("resources/dummy.css", 1); + t.done(); + })); +</script>